package com.ruoyi.network.controller;

import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.network.domain.NetworkEdge;
import com.ruoyi.network.service.INetworkEdgeService;

/**
 * 边缘端Controller
 * 
 * @author ruoyi
 * @date 2024-09-18
 */
@RestController
@RequestMapping("/network/edge")
public class NetworkEdgeController extends BaseController
{
    @Autowired
    private INetworkEdgeService networkEdgeService;
    @Autowired
	private ApplicationEventPublisher eventPublisher;
    
    /**
     * 查询边缘端列表
     */
    @PreAuthorize("@ss.hasPermi('network:edge:list')")
    @GetMapping("/queryList")
    public TableDataInfo queryList(@RequestParam Map<String, Object> param) throws Exception
    {
		startPage();
		List<Map<String, Object>> list = networkEdgeService.queryList(param);
		return getDataTable(list);
    }

    /**
     * 查询边缘端列表
     */
    @PreAuthorize("@ss.hasPermi('network:edge:list')")
    @GetMapping("/list")
    public TableDataInfo list(NetworkEdge networkEdge)
    {
        startPage();
        List<NetworkEdge> list = networkEdgeService.selectList(networkEdge);
        return getDataTable(list);
    }

    /**
     * 导出边缘端列表
     */
    @PreAuthorize("@ss.hasPermi('network:edge:export')")
    @Log(title = "边缘端", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, NetworkEdge networkEdge)
    {
        List<NetworkEdge> list = networkEdgeService.selectList(networkEdge);
        ExcelUtil<NetworkEdge> util = new ExcelUtil<NetworkEdge>(NetworkEdge.class);
        util.exportExcel(response, list, "边缘端数据");
    }

    /**
     * 获取边缘端详细信息
     */
    @PreAuthorize("@ss.hasPermi('network:edge:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(networkEdgeService.selectById(id));
    }

    /**
     * 新增边缘端
     */
    @PreAuthorize("@ss.hasPermi('network:edge:add')")
    @Log(title = "边缘端", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody NetworkEdge networkEdge)
    {
        return toAjax(networkEdgeService.insert(networkEdge));
    }

    /**
     * 修改边缘端
     */
    @PreAuthorize("@ss.hasPermi('network:edge:edit')")
    @Log(title = "边缘端", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody NetworkEdge networkEdge)
    {
        AjaxResult ajax = toAjax(networkEdgeService.update(networkEdge));
        networkEdgeService.change(networkEdge);
		return ajax;
    }
    
    /**
     * 激活边缘端
     */
    @PreAuthorize("@ss.hasPermi('network:edge:edit')")
    //@Log(title = "边缘端", businessType = BusinessType.UPDATE)
    @PutMapping("/change")
    @Transactional
    public AjaxResult change(@RequestBody NetworkEdge networkEdge)
    {
    	return networkEdgeService.change(networkEdge);
    }
    
    /**
     * 删除边缘端
     */
    @PreAuthorize("@ss.hasPermi('network:edge:remove')")
    @Log(title = "边缘端", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(networkEdgeService.deleteByIds(ids));
    }
}
